package com.chixing.controller;

import com.chixing.entity.Product;
import com.chixing.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller  //<bean id="productController" class=" com.chixing.controller.productController"/>
public class ProductController {
    @Autowired //按照类型type到spring容器中匹配 找productService他的实现子类对象
    @Qualifier("productServiceImplA") //指定用哪个实现子类  因为两个ProductService的实现子类都会注入到容器中，不加Qualifier不知道要用哪个实现子类
    private ProductService productService;

//    public ProductController(){
//        System.out.println("ProductController 无参构造函数");
//    }
//
//    public ProductController(ProductService productService) {
//        System.out.println("ProductController 有参构造");
//        this.productService = productService;
//    }
//
//    public void setProductService(ProductService productService) {
//        System.out.println("setProductService 方法....");
//        this.productService = productService;
//    }


    public Product getById(Integer id){
        System.out.println("ProductController getById");
        return productService.getById(id);
    }
}
